﻿namespace Infrastructure.Utils
{
    public class FormatString
    {
        #region 组合信息
        /// <summary>
        /// 组合信息 eg:FormatStr.ComInfo("-","浙江","","阿里") >> "浙江-阿里"
        /// </summary>
        /// <param name="separator"></param>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string CombineInfo(string separator, params string[] str)
        {
            str = str.Where(s => !string.IsNullOrEmpty(s)).ToArray();
            return string.Join(separator, str);
        }
        #endregion
    }

    #region 身份证信息
    public class IdCard
    {
        /// <summary>
        /// 通过身份证字符串获取生日，性别信息
        /// </summary>
        /// <param name="IdCardNo"></param>
        /// <returns></returns>
        public static IdCard Info(string IdCardNo)
        {
            if (!RegexPattern.IsIdCard(IdCardNo)) return null;
            var credInfo = new IdCard();
            credInfo.DateOfBirth = DateTime.ParseExact(IdCardNo.Substring(6, 8), "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
            credInfo.GenderCode = Convert.ToInt16(IdCardNo.Substring(16, 1)) % 2 == 1 ? 1 : 0;
            credInfo.GenderName = Convert.ToInt16(IdCardNo.Substring(16, 1)) % 2 == 1 ? "男" : "女";
            return credInfo;
        }
        /// <summary>
        /// 出生日期
        /// </summary>
        public DateTime DateOfBirth { get; set; }
        /// <summary>
        /// 男/女
        /// </summary>
        public string GenderName { get; set; }
        /// <summary>
        /// 男1/女0
        /// </summary>
        public int GenderCode { get; set; }
    }
    #endregion
}
